﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class AudioManager : MonoBehaviour
{
    static AudioManager audioManager;
    [Header("AuidoSource")]
    AudioSource bgmAudioSource;
    AudioSource fxAudioSource;
    AudioSource playerAudioSource;

    [Header("Clip")]
    public AudioClip Bgm1Clip;
    public AudioClip Bgm2Clip;
    public AudioClip Bgm3Clip;
    public AudioClip OrganClip;
    public AudioClip PullClip;

    private void Awake()
    {
        bgmAudioSource = gameObject.AddComponent<AudioSource>();
        playerAudioSource = gameObject.AddComponent<AudioSource>();
        fxAudioSource = gameObject.AddComponent<AudioSource>();
    }

    void Start()
    {
        if (audioManager != null)
        {
            return;
        }
        audioManager = this;

        PlayerBgm();
    }

    public void PlayerBgm()
    {
        if (SceneManager.GetActiveScene().buildIndex == 0)
        {
            Debug.Log("Level 01");
            bgmAudioSource.clip = Bgm1Clip;
            bgmAudioSource.loop = true;
        }
        else if (SceneManager.GetActiveScene().buildIndex == 1)
        {
            Debug.Log("Level 02");
            bgmAudioSource.clip = Bgm2Clip;
            bgmAudioSource.loop = true;
        }
        else if (SceneManager.GetActiveScene().buildIndex == 2)
        {
            Debug.Log("Level 03");
            bgmAudioSource.clip = Bgm3Clip;
            bgmAudioSource.loop = true;
        }
        bgmAudioSource.Play();
    }

    public static void PlayerOrgan()
    {
        audioManager.fxAudioSource.clip = audioManager.OrganClip;
        audioManager.fxAudioSource.Play();
    }
    public static void PlayerPullClip()
    {
        audioManager.playerAudioSource.clip = audioManager.PullClip;
        audioManager.playerAudioSource.Play();
    }
}
